<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #canvas {
            margin: auto;
            display: block;
            box-shadow: 0 5px 5px rgba(0, 0, 0, .5);
            background-color: aliceblue;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="500" height="800">
    </canvas>
    <script>
        var canvas = document.querySelector("#canvas");
        console.log(canvas);
        var ctx = canvas.getContext('2d');


        
      canvas.onclick = function(){
            canvas.onmousedown = function (e) {
            console.log("鼠标移动了");
            console.log(e.offsetX, e.offsetY);
            ctx.fillStyle = 'red';
            ctx.beginPath();
            ctx.arc(e.offsetX, e.offsetY, 10, 0, 2 * Math.PI);
            ctx.fill();
          }  
        }
      
        
    </script>
</body>

</html>